package com.workplan.client.widgets.historymodal;

import java.util.Date;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

import com.workplan.client.widgets.historyitem.HistoryItem;
import com.workplan.client.widgets.historyitem.HistoryItemPresenter;
import com.workplan.client.widgets.historyitem.HistoryItemPresenterImpl;
import com.workplan.shared.datamodel.employeeshift.EmployeeShiftDataModel;

public class HistoryModalPresenterImpl extends
		WidgetPresenter<HistoryModalPresenter.Display> implements
		HistoryModalPresenter {

	public HistoryModalPresenterImpl(Display display, EventBus eventBus) {
		super(display, eventBus);
	}

	@Override
	public void setEmployeeId(Integer id) {
		// TODO fetch data from server
	}

	@Override
	public void show(boolean show) {
		display.show(show);
	}

	@Override
	protected void onBind() {
		display.setName("Nadav Greenberg");
		populateDummyData();
	}

	private void populateDummyData() {
		for (int i = 0; i < 55; i++) {
			if (i % 4 == 0) {
				display.addMonthItem("May 2010");
			}
			HistoryItemPresenter.Display historyItem = new HistoryItem();
			HistoryItemPresenter historyItemPresenter = new HistoryItemPresenterImpl(
					historyItem, eventBus);
			historyItemPresenter.bind();
			Date start = new Date();
			start.setTime(start.getTime() - 1000 * 60 * 60 * 10);
			Date end = new Date();
			end.setTime(end.getTime() - 1000 * 60 * 60 * 4);
			historyItemPresenter.setModel(new EmployeeShiftDataModel(1,
					new Date(), start, end));
			display.addShiftItem(historyItemPresenter.getDisplay());
		}

	}

	@Override
	protected void onUnbind() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onRevealDisplay() {
	}

}
